package com.melody.rest.model;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResJson<T> implements Serializable {

    private int code;

    private String msg;

    private T data;

    public static ResJson yes() {
        return yes("");
    }

    public static ResJson yes(Object o) {
        return new ResJson(ResCode.SUCCESS, o);
    }

    public static ResJson no(ResCode resCode) {
        return new ResJson(resCode);
    }

    public static  ResJson no(ResCode resCode, Object o) {
        return new ResJson(resCode, o);
    }

    public ResJson(){}

    public ResJson(ResCode resCode) {
        setResCode(resCode);
    }

    public ResJson(ResCode resCode, T data) {
        setResCode(resCode);
        this.data = data;
    }

    public void setResCode(ResCode resCode) {
        this.code = resCode.getCode();
        this.msg = resCode.getMsg();
    }

    @Override
    public String toString() {
        return "ResJson{" +
                "\"code\":" + code +
                ",\"msg\":" + msg + '\'' +
                ",\"data\":" + data +
                '}';
    }
}
